/**
 * org.assess.oa.system.action.TbPostAction
 */
package org.assess.oa.system.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.assess.core.action.BaseAction;
import org.assess.core.service.ServiceResult;
import org.assess.oa.system.bean.TbPost;
import org.assess.oa.system.bean.TbPostRole;
import org.assess.oa.system.service.TbPostService;

/**
 * @description 岗位管理的Action实现类
 * @author XiaLongxiang
 * @createtime 2012-6-5 下午4:11:35
 */
public class TbPostAction extends BaseAction {
    /** 序列化号 */
    private static final long serialVersionUID = -1088761952294845398L;
    
    /** 角色ID字符串 */
    private String roleString;
    
    /** TbPost的JavaBean对象 */
    private TbPost post;
    
    /** TbPostRole的list对象 */
    private List<TbPostRole> postroleList;
    
    /** 岗位管理的Service层对象 */
    private TbPostService tbPostService;
    
    /**
     * 跳转到岗位管理页面
     * @return
     */
    public String showPostJsp() {
        return SUCCESS;
    }
    
    /**
     * 分页查询岗位信息
     * @return
     */
    public String listPost() {
        String jsonString = this.tbPostService.queryTbPostAsList(super.getPage(), super.getRows(), post);
        super.setJsonString(jsonString);
        return SUCCESS;
    }
    
    /**
     * 加载岗位信息
     * @return
     */
    public String loadPost() {
        if (post != null && StringUtils.isNotBlank(post.getPost_id())) {
            super.setEdit(true);
            post = this.tbPostService.queryTbPostById(post.getPost_id());
        }
        else {
            super.setEdit(false);
        }
        
        this.postroleList = this.tbPostService.queryTbPostRoleByPostIdAsList(post, true);
        return SUCCESS;
    }
    
    /**
     * 保存岗位信息
     * @return
     */
    public String savePost() {
        try {
            ServiceResult result = this.tbPostService.saveTbPost(post, roleString, super.isEdit());
            if (result == ServiceResult.save_success) {
                super.setMessage(super.getText("G_SAVE_001", new String[] {super.getText("ST_POST_000")}));
            }
            else {
                super.setMessage(super.getText("G_SAVE_002", new String[] {super.getText("ST_POST_000")}));
            }
        }
        catch (Exception ex) {
            super.setMessage(super.getText("G_SAVE_002", new String[] {super.getText("ST_POST_000")}));
        }
        
        return SUCCESS;
    }
    
    /**
     * 删除岗位信息
     * @return
     */
    public String deletePost() {
        if (post == null) {
            post = new TbPost();
        }
        
        post.setPost_id(super.getId());
        
        try {
            String jsonString = this.tbPostService.deleteTbPost(post);
            super.setJsonString(jsonString);
        }
        catch (Exception ex) {
            
        }
        
        return SUCCESS;
    }
    
    public void setRoleString(String roleString) {
        this.roleString = roleString;
    }
    
    public TbPost getPost() {
        return post;
    }
    
    public void setPost(TbPost post) {
        this.post = post;
    }
    
    public List<TbPostRole> getPostroleList() {
        return postroleList;
    }
    
    public void setTbPostService(TbPostService tbPostService) {
        this.tbPostService = tbPostService;
    }
}
